{% extends TEMPLATE_BASE %}
{% block title %}Confirm Vote{% endblock %}

{% block content %}
<script language="javascript">
$(document).ready(function() {
  $('#waiting_div').hide();
});

function show_waiting() {
  $('#all_forms').hide();
  $('#waiting_div').show();
}

// FIXME: set this to false once it's clear how to set it back to true
// so that it's not easy to forget to cast a ballot
var ready_to_unload = true;

window.onbeforeunload = function(evt) {
  if (ready_to_unload)
    return;

  if (typeof evt == 'undefined') {
    evt = window.event;
  }
  
  var message = "You have not yet cast your ballot! Make sure to complete the voting process if you want your vote to count.";

  if (evt) {
    evt.returnValue = message;
  }
  
  return message;
};

</script>
<h1>Don't go yet!<br />Your ballot has not yet been cast.</h1>

<div id="waiting_div">
    Verifying and Casting your ballot<br />
    <img src="/static/helios/loading.gif" />
</div>

<div style="word-wrap: break-word; width: 90vw;">
Your ballot tracker is:<br>
<b>{{vote_fingerprint}}</b>
<br><br>
</div>

<div id="all_forms">

{% if voter %}

{% include "_castconfirm_docast.html" %}

{% else %}

{% if show_password %}
{% with cast_ballot="1" %}
{% include "_castconfirm_password.html" %}
{% endwith %}

{% else %}

{% if user %}
<h1>Sorry!<h1>
<b>Sorry, you are <em>
  {% if election.openreg %}
    <u>not eligible</u></em> for this election.
  {% else %}
    not registered</em> for this election, and registration is closed.
  {% endif %}
  </b><br /></p>
<p>
    [<a href="{% url "election@view" election.uuid %}">return to the main election page</a>]
</p>
{% else %}
<p>
{% if election.openreg %}

  {% if election.eligibility %}
  {% else %}
   This election is open to <em>anyone</em>, so log in with your preferred account.
  {% endif %}

{% else %}
  This election is only open to <em>registered voters</em>, so log in with
  the same account you registered with.
{% endif %}
</p>

{{login_box|safe}}

<br />
Don't worry, we'll remember your ballot while you log in.
{% endif %}

{% endif %}
</p>
{# this closes the IF ELSE of this being password_only #}
{% endif %}

</div>

{% endblock %}
